<template>
  <div>
    <h1>Page:/home/message</h1>
    <ul>
      <li>query传值</li>
      <!-- <router-link :to="`/home/message/detail/${m.id}/${m.title}`">{{m.title}}</router-link>&nbsp;&nbsp; -->

      <li v-for="m in messageList" :key="m.id">
        <router-link :to="{
          path: '/home/homeMessage/msgQueryDetail',
          query:{
            id:m.id,
            title:m.title}  }"> {{ m.title }}
        </router-link>
        <button @click="pushShow(m)">push查看(浏览器历史栈)</button>
        <button @click="replaceShow(m)">replace查看(跳转及删除)</button>
      </li>

    </ul>
    <ul>
      <li>param传值</li>
      <!-- <router-link :to="`/home/message/detail/${m.id}/${m.title}`">{{m.title}}</router-link>&nbsp;&nbsp; -->

      <li v-for="m in messageList" :key="m.id">

        <router-link :to="{
          name: 'home/homeMessage/msgParamsDetail',


          params:{
            id:m.id,
            title:m.title}  }"> {{ m.title }}
        </router-link>
      </li>
    </ul>
    <ul>
      <li>param传值, 路由prop 控制</li>

      <li v-for="m in messageList" :key="m.id">

        <router-link :to="{
          // path: '/home/homeMessage/msgParamsDetail',
            name: 'home/homeMessage/msgPropParams',


           params:{
            id:m.id,
            info:m.title}  }"> {{ m.title }}
        </router-link>

      </li>
    </ul>

    <router-view></router-view>
  </div>
</template>

<script>
import {useRoute, useRouter} from 'vue-router'

export default {

  name: "HomeMessage",
  setup() {
    const messageList = [
      {id: '001', title: '消息001'},
      {id: '002', title: '消息002'},
      {id: '003', title: '消息003'}
    ]
    // const route = useRoute()
    const router = useRouter()

    function pushShow(m) {
      router.push({
        path: '/home/homeMessage/msgQueryDetail',
        query: {
          id: m.id,
          title: m.title
        }
      })
    }

    function replaceShow(m) {
      router.replace({
        path: '/home/homeMessage/msgQueryDetail',
        query: {
          id: m.id,
          title: m.title
        }
      })
    }

    //返回一个对象（常用）
    return {messageList, pushShow, replaceShow}
  }
}
</script>

<style scoped>
div {
  background: #a2d9d0;
  padding: 10px;
}
</style>